import request from '@/src/basic/utils/request.js'
import { getUserInfo } from '@/src/basic/utils/user'

function handleParams(param) {
  let paramsUrl = ''
  for (const item in param) {
    let val = param[item]
    let str = `${item}=${val}&`
    paramsUrl += str
  }
  paramsUrl = paramsUrl.slice(0, paramsUrl.length - 1)
  return paramsUrl
}


// /merchant/changePasswordByOriginalPassword用密码修改密码
export const changePasswordByOriginalPassword = async params => {
  const { data } = await request.post(`/merchant/merchant/changePasswordByOriginalPassword?${handleParams(params)}`)
  return data
}
// /sms/send/free/vericode发送短信验证码
export const getCode = async phone => {
  const params = {
    phone: phone,
    loginType: 1
  }
  const { data } = await request.get('/basic/sms/send/free/vericode', params)
  return data
}
// /merchant/testOriginalPhone验证原手机
export const testOriginalPhone = async params => {
  const { data } = await request.post(`/merchant/merchant/testOriginalPhone?${handleParams(params)}`)
  return data
}
// /merchant/bindingOriginalPhone绑定新手机
export const bindingOriginalPhone = async params => {
  const { data } = await request.post(`/merchant/merchant/bindingOriginalPhone?${handleParams(params)}`)
  return data
}
